<!--
*@Author: QWP
*@Description: 外派人员回司信息编辑
*@Date: 2024-07-08 17:04:38
-->
<template>
  <u-dialog v-bind="$attrs"
    :confirmLoading="formLoading"
    destroyOnClose
    @submit="submit"
    @close="dialogClose">
    <u-form :elements="formEls"
      :model="form"
      :gutter="16"
      :loading="formLoading"
      @formChange="getUser"
      ref="formRef">
    </u-form>
  </u-dialog>
</template>

<script lang='ts' setup>
import { ref, reactive, computed, onMounted, h, useAttrs, watch } from 'vue' 
import { useLoginStore,  useBaseStore } from '@/store'
import { storeToRefs } from 'pinia'
import { useRoute, useRouter } from 'vue-router'
import { _IFormEl, _IExtra } from '@/src/components/common/form/interface';
import { FormInstance, FormItemProps } from 'ant-design-vue';
import { HomeOutlined, FileTextOutlined, UploadOutlined } from '@ant-design/icons-vue';
import { TreeProps } from 'ant-design-vue/es/vc-tree';
import { ColumnProps } from 'ant-design-vue/es/table';
import { _IColumnProps } from '@/components/common/tableEdit/interface.ts'
import { fileCols } from '@/common/model/fileCols'
import { cloneDeep } from 'lodash'
import { techLevels, numberToText } from '@/common/model/base'
import { alertC, messageC, numberC, isValue } from '@/util/common'
import { useSetViewPath } from '@/hooks/useFile'
import { insureFormEls, insureRecordCols } from './data.ts'

interface Props {
  keyid?: string
}
const props = defineProps<Props>()
const route = useRoute()
const attrs = useAttrs()
const { userInfo } = storeToRefs(useLoginStore())
const { deptData } = storeToRefs(useBaseStore())

const emits = defineEmits(['success'])

// 表单相关信息
const formRef = ref<FormInstance>()
const form = ref({})
const formLoading = ref<boolean>(false)
const formItemProps: FormItemProps & _IExtra = {
  labelWidth: '130px',
  colon: false
}
const formEls: Array<_IFormEl> = reactive([
  { label: '人员姓名', key: 'key1', col: { span: 24,}, element: 'input', 
    formItemProps: { ...formItemProps, required: true },
    componentProps: { disabled: true }
  },
  { label: '派遣事由', key: 'key8', col: { span: 24,}, element: 'textarea', 
    formItemProps: { ...formItemProps, required: true },
    componentProps: { disabled: true }
  },
  { label: '派遣期限', key: 'key3', col: { span: 24 }, element: 'input', 
    formItemProps: { ...formItemProps, required: true },
    componentProps: { disabled: true }
  },
  { label: '派遣性质', key: 'key4', col: { span: 24 }, element: 'select', 
    formItemProps: { ...formItemProps, required: true },
    componentProps: {
      options: [
        {label: '购买服务', value: 1},
        {label: '非购买服务', value: 2},
        {label: '其他', value: 3},
      ],
      onChange(e) {
        if(e !== 3) form.value['key5'] = ''
      }
    }
  },
  { label: '派遣性质备注', key: 'key5', col: { span: 24 }, element: 'input', 
    formItemProps: { ...formItemProps, required: true }, hide: computed(() => form.value['key4'] != 3)
  },
  { label: '回司日期', key: 'key6', col: { span: 24,}, element: 'datepicker', 
    formItemProps: { ...formItemProps, required: true },
  },
])

// 确认提交
const submit = async () => {
}

// 初始化默认保存传递的数据
const initBaseInfo = () => {
  form.value = {
    fkuserid: userInfo.value["userId"],
    fkusername: userInfo.value["name"],
    fkdeptid: userInfo.value["deptId"],
    redeptname: userInfo.value["deptName"],
    ssdeptid: userInfo.value["deptId"],
    ssdeptname: userInfo.value["deptName"],
    fkunitsid: userInfo.value["unitId"],
    unitName: userInfo.value["unitName"],
  }
}

// 弹窗关闭
const dialogClose = () => {
  formRef.value.form.resetFields()
  form.value = {}
}

watch(() => attrs.open, async (nval, oval) => {
  if (nval == true) {
  }
})
</script>

<style lang='scss' >
</style>